package com.chinapost.action;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.ModelDriven;
import com.chinapost.vo.Json;
import com.chinapost.vo.Yglb;
import com.chinapost.service.YglbServiceI;

@Action(value="yglbAction",results = { @Result(name = "yglbManager", location = "/jsp/yglb/yglbManager.jsp"), 
									   @Result(name = "yglbAdd", location = "/jsp/yglb/yglbAdd.jsp"), 
									   @Result(name = "yglbEdit", location = "/jsp/yglb/yglbEdit.jsp") })
public class YglbAction extends BaseAction implements ModelDriven<Yglb> {
	
	private Yglb yglb=new Yglb();
	@Autowired
	private YglbServiceI yglbService;
	

	@Override
	public Yglb getModel() {
		return yglb;
	}

	public String yglbManager(){
		return "yglbManager";
	}
	
	public String yglbAdd(){
		return "yglbAdd";
	}
	
	public String yglbEdit(){
		return "yglbEdit";
	}
	
	public void add(){
		Json j = new Json();
		try {
			yglbService.add(yglb);
			j.setSuccess(true);
			j.setMsg("添加成功！");
		} catch (Exception e) {
			j.setMsg("添加失败！");
		}
		super.writeJson(j);
	}
	
	public void do_datagrid() {
		super.writeJson(yglbService.datagrid(yglb));
	}
	
	public void delete(){
		Json j = new Json();
		try {
			yglbService.delete(yglb);
			j.setSuccess(true);
			j.setMsg("删除成功！");
			j.setObj(yglb.getCid());
		} catch (Exception e) {
			j.setMsg("删除失败！");
		}
		super.writeJson(j);
	}
	
	public void edit(){
		Json j = new Json();
		try {
			yglbService.edit(yglb);
			j.setSuccess(true);
			j.setMsg("编辑成功!");
		} catch (Exception e) {
			j.setMsg("编辑失败！");
		}
		writeJson(j);
	}
	
	public void do_combobox() {
		super.writeJson(yglbService.combobox());
	}
}
